package com.ruoyi.web.controller.shop;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.shop.domain.PrintLog;
import com.ruoyi.shop.service.IPrintLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 打印记录Controller
 * 
 * @author ruoyi
 * @date 2025-11-11
 */
@RestController
@Api(tags = "打印记录模块")
@RequestMapping("/shop/printLog")
public class PrintLogController extends BaseController
{
    @Autowired
    private IPrintLogService printLogService;

    /**
     * 查询打印记录列表
     */
    @PreAuthorize("@ss.hasPermi('shop:printLog:list')")
    @ApiOperation("查询打印记录列表")
    @GetMapping("/list")
    public TableDataInfo list(PrintLog printLog)
    {
        startPage();
        List<PrintLog> list = printLogService.selectPrintLogList(printLog);
        return getDataTable(list);
    }

    /**
     * 导出打印记录列表
     */
    @PreAuthorize("@ss.hasPermi('shop:printLog:export')")
    @Log(title = "打印记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PrintLog printLog)
    {
        List<PrintLog> list = printLogService.selectPrintLogList(printLog);
        ExcelUtil<PrintLog> util = new ExcelUtil<PrintLog>(PrintLog.class);
        util.exportExcel(response, list, "打印记录数据");
    }

    /**
     * 获取打印记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:printLog:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("根据ID查询打印记录详情")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(printLogService.selectPrintLogById(id));
    }

    /**
     * 新增打印记录
     */
    @PreAuthorize("@ss.hasPermi('shop:printLog:add')")
    @Log(title = "打印记录", businessType = BusinessType.INSERT)
    @ApiOperation("新增打印记录")
    @PostMapping
    public AjaxResult add(@RequestBody PrintLog printLog)
    {
        printLog.setUserId(getLoginUser().getUserId());
        printLog.setCreateBy(getLoginUser().getUsername());
        return toAjax(printLogService.insertPrintLog(printLog));
    }

    /**
     * 修改打印记录
     */
    @PreAuthorize("@ss.hasPermi('shop:printLog:edit')")
    @Log(title = "打印记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PrintLog printLog)
    {
        return toAjax(printLogService.updatePrintLog(printLog));
    }

    /**
     * 删除打印记录
     */
    @PreAuthorize("@ss.hasPermi('shop:printLog:remove')")
    @Log(title = "打印记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(printLogService.deletePrintLogByIds(ids));
    }
}
